package com.jade.store.wechat.biz.business.Jssdk;

import com.jade.store.wechat.biz.common.Log;
import com.jade.store.wechat.biz.common.Util;
import com.jade.store.wechat.biz.protocol.Jssdk.GetJsTicketReq;
import com.jade.store.wechat.biz.protocol.Jssdk.GetJsTicketRes;
import com.jade.store.wechat.biz.service.jssdk.GetJsTicketService;
import org.slf4j.LoggerFactory;

/**
 * Created with IntelliJ IDEA.
 * User: jinya
 * Date: 2016/12/14
 * Time: 19:38
 * TEL :17701640710   MAIL:2009_jinya@163.com
 * To change this template use File | Settings | File Templates.
 */
public class GetJsTicketBusiness {
    private GetJsTicketService _service;
    //打log用
    private static Log log = new Log(LoggerFactory.getLogger(GetJsTicketBusiness.class));
    //执行结果
    private static String result = "";

    public GetJsTicketBusiness(String appid) throws IllegalAccessException, ClassNotFoundException, InstantiationException {
        _service = new GetJsTicketService(appid);
    }
    /**
     * 调用退款业务逻辑
     * @param req 这个数据对象里面包含了API要求提交的各种数据字段
     * @throws Exception
     */
    public GetJsTicketRes run(GetJsTicketReq req) throws Exception {
        //API返回的数据
        String resStr;
        long costTimeStart = System.currentTimeMillis();
        log.i("GET-请求JS-TICKET：");
        resStr = _service.request(req);
        long costTimeEnd = System.currentTimeMillis();
        long totalTimeCost = costTimeEnd - costTimeStart;
        log.i("GET-JS-TICKET请求总耗时：" + totalTimeCost + "ms");
        log.i(resStr);
        GetJsTicketRes res = (GetJsTicketRes) Util.getObjectFromJson(resStr, GetJsTicketRes.class);
        return res;
    }
    public String getResult() {
        return result;
    }
}
